package cn.stu.projectsummit.blog.controller;

import cn.stu.projectsummit.base.response.JsonResult;
import cn.stu.projectsummit.blog.pojo.dto.BlogQuery;
import cn.stu.projectsummit.blog.pojo.dto.BlogSaveParam;
import cn.stu.projectsummit.blog.pojo.vo.BlogVO;
import cn.stu.projectsummit.blog.service.BlogService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@RequestMapping("v1/blog")
public class BlogController {
    @Autowired
    BlogService blogService;

    @GetMapping("select")
    public JsonResult selectBlog(BlogQuery blogQuery){
        log.debug("查询帖子信息 blogQuery={}",blogQuery);
        List<BlogVO> listBlogVO = blogService.selectBlog(blogQuery);
        return JsonResult.ok(listBlogVO);
    }
    @PostMapping("update")
    public JsonResult saveBlog(BlogSaveParam blogSaveParam){
        log.debug("修改帖子信息 blogSaveParam={}",blogSaveParam);
        blogService.saveBlog(blogSaveParam);
        return JsonResult.ok();
    }
    @PostMapping("insert")
    public JsonResult insertBlog(BlogSaveParam blogSaveParam){
        log.debug("保存帖子信息 blogSaveParam={}",blogSaveParam);
        blogService.insertBlog(blogSaveParam);
        return JsonResult.ok();
    }

    @PostMapping("delete/{blogId}")
    public JsonResult deleteBlog(@PathVariable Long blogId){
        log.debug("删除帖子信息 blogId={}",blogId);
        blogService.deleteBlog(blogId);
        return JsonResult.ok();
    }
}
